/**
 * Created by xu on 2016/3/18.
 */

function checkedme(em){
    var c=$("#checkedmeI").hasClass("active");
    if (c){
        clearCook();
    }
}


function Encrypt(word){
    var key = CryptoJS.enc.Utf8.parse("0102030405060708");
    var iv  = CryptoJS.enc.Utf8.parse('0102030405060708');
    var srcs = CryptoJS.enc.Utf8.parse(word);
    var encrypted = CryptoJS.AES.encrypt(srcs, key, { iv: iv,mode:CryptoJS.mode.CBC});
    return encrypted.toString();
}
function Decrypt(word){
    var key = CryptoJS.enc.Utf8.parse("0102030405060708");
    var iv  = CryptoJS.enc.Utf8.parse('0102030405060708');
    var decrypt = CryptoJS.AES.decrypt(word, key, { iv: iv,mode:CryptoJS.mode.CBC});
    return CryptoJS.enc.Utf8.stringify(decrypt).toString();
}
function clearCook(){
    $.cookie('TemBincookieName1122553547556',null);
    $.cookie('TemBincookiePass1122553547556',null);
}

function setUserInfoCookies(){
    //$.cookie('cookieName','cookieValue',{expires:7,path:'/',domain: 'chuhoo.com',secure:false,raw:false});
    $.cookie('TemBincookieName1122553547556',(Encrypt($("input[name=userName]").val())),{expires:7});
    $.cookie('TemBincookiePass1122553547556',(Encrypt($("input[name=pwd]").val())),{expires:7});
    //注：domain：创建cookie所在网页所拥有的域名；secure：默认是false，如果为true，cookie的传输协议需为https；raw：默认为false，读取和写入时候自动进行编码和解码（使用encodeURIComponent编码，使用decodeURIComponent解码），关闭这个功能，请设置为true。
}

function readUserInfoCookies(){
    var namet=$.cookie('TemBincookieName1122553547556');
    var passt=$.cookie('TemBincookiePass1122553547556');
    if(namet!=null){
        namet=Decrypt(namet);
        $("input[name=userName]").val(namet);
    }
    if(passt!=null){
        passt=Decrypt(passt);
        $("input[name=pwd]").val(passt)
        $("#checkedmeI").addClass("active");
    }
}